package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void insertBatch(List<OrderDetail> orderDetailList);

    @Select("select * from orders where number = #{number}")
    List<Orders> list(Orders order);

    void update(Orders order);


    Page<Orders> listByPage(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> listDetailsByOrderId(Long id);

    OrderStatisticsVO statistics();

    @Update("update orders set status = #{status} where id = #{id}")
    void changeStatus(Orders  orders);

    @Update("update orders set status = #{status}, rejection_reason = #{rejectionReason}, cancel_time = #{cancelTime}, cancel_reason = #{cancelReason} where id = #{id}")
    void rejection(Orders orders);


    Page<Orders> userPageQuery(OrdersPageQueryDTO ordersPageQueryDTO);


    @Select("select * from orders where status = #{status} and order_time < #{localDateTime}")
    List<Orders> listByTimeOut(Integer status, LocalDateTime localDateTime);


    Integer countByMap(Map map);

    @Select("select sum(amount) from orders where order_time between #{begin} and #{end} and status = #{status}")
    Double sumByMap(Map map);
}
